// JavaScript Document

var xhttp;
var xhttp2;
var xhttp3;

function GetXmlHttpObject()
{ 
/*
	 var objXMLHttp=null
	 if (window.XMLHttpRequest)
	  {
	  objXMLHttp=new XMLHttpRequest()
	  }
	 else if (window.ActiveXObject)
	  {
	  objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	  }
	 return objXMLHttp
	 */
	 return CrossXHR();
}

function CrossXHR() {
 var crossxhr = false;
 if(window.XMLHttpRequest) {
  crossxhr = new XMLHttpRequest();
  if(crossxhr.overrideMimeType) {
   crossxhr.overrideMimeType('text/xml');
 }
 } else if(window.ActiveXObject) {
  try {
   crossxhr = new ActiveXObject('Msxml2.XMLHTTP');
  } catch(e) {
   try {
    crossxhr = new ActiveXObject('Microsoft.XMLHTTP');
   } catch(e) {
    crossxhr = false;
   }
  }
 }
 return crossxhr;
}

function updateDB(TblName, ID, CName, Value)
{
	var rt1 = updateDB2(TblName, ID, CName, Value);
	var rt2 = setLogReport(ID);
	var rt3 = setShortOverMsg(ID);

	return true;

}

function updateDB2(TblName, ID, CName, Value)
{
	xhttp = null;
  	xhttp = GetXmlHttpObject();
	if (xhttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	actionURL = "action.php?TblName=" + TblName+"&CName="+CName+"&ID="+ID+"&Value="+Value+"&Action=100";
	//alert(actionURL );
	//xhttp.open("GET", actionURL,true);
	//
	xhttp.open("POST", actionURL, true);
	//
	//xhttp.onreadystatechange = ShowRespose(xhttp);	
	xhttp.send(null);

	return true;

}



//function setLogReport2(ParentId, IPPSaleAmt,XReadingAmt){
function setLogReport2(ParentId){
 	xhttp = null;
	var today=new Date();
  	xhttp = GetXmlHttpObject();
	if (xhttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return false;
	} 
	//actionURL = "shortover_msg.php?ID="+ParentId;
	//actionURL = "SummaryReportInfo2.php?ID="+ParentId+"&IPPSaleAmt="+IPPSaleAmt+"&XReadingAmt="+XReadingAmt;
	
	actionURL = "SummaryReportInfo2.php?ID="+ParentId;
	
	//alert(actionURL);

	xhttp.open("post", actionURL,true);
	xhttp.send(null);

 	xhttp.onreadystatechange = function(){ 
			if(xhttp.readyState == 4){ 
			//document.getElementById('logreport').innerHTML ='oOo'+today.getSeconds();
			//document.getElementById('logreport').innerHTML = today.getSeconds()+'<br>'+xhttp.responseText; 
			document.getElementById('logreport').innerHTML = xhttp.responseText; 
			//alert(xhttp.responseText);
			} 
	}
//alert(xhttp.responseText);
	
	//xhttp = null; 

	return true;

}


function update_shortover(ParentId){
 	xhttp2 = null;
	var today=new Date();
  	xhttp2 = GetXmlHttpObject();
	if (xhttp2==null)
	{
		alert ("Browser does not support HTTP Request");
		return false;
	} 
	actionURL = "shortover_msg.php?ID="+ParentId;
	xhttp2.open("GET", actionURL,true);
	xhttp2.send(null);

 	xhttp2.onreadystatechange = function(){ 
			if(xhttp2.readyState == 4){ 
			document.getElementById('overshrtmsg').innerHTML = xhttp2.responseText; 
			//document.getElementById('overshrtmsg').innerHTML = today.getSeconds()+'<br>'+xhttp2.responseText; 
			} 
	}
	return true;
}



function update_db(ParentId, LookupId, obj, scope, cn){
	var rt1 = update_db2(ParentId, LookupId, obj, scope, cn);
	var rt2 = setLogReport(ParentId);
	var rt3 = setShortOverMsg(ParentId);
	return true;

}


function update_db2(ParentId, LookupId, obj, scope, cn){
	//alert(obj.value+" "+ParentId+" "+LookupId+" "+scope);
  	val=obj.value;
	xhttp3 = null;
  	xhttp3 = GetXmlHttpObject();
	if (xhttp3==null)
	{
		alert ("Browser does not support HTTP Request")
		return false;
	} 
	actionURL = "action2.php?Tbl=" + scope+"&CName="+cn+"&ID="+ParentId+"&Value="+val+"&look="+LookupId;
	//
	//alert(actionURL);
	
	xhttp3.open("GET", actionURL,true);
	//xhttp.open("POST", actionURL);
	//xhttp.onreadystatechange = ShowRespose(xhttp);	
	xhttp3.send(null);
	
	return true;

}

function deleteAll(TblName, ID, Scope)
{
	var userresponse =	confirm("Do you want delete all cash log entries?");
	if(userresponse == true ){
		window.location.href = "delete.php?ParentID="+ID+"&TblName=" + TblName+"&ID="+ID+"&Action="+Scope;	
		return true;
	}
}

function deleteDB(ParentID, TblName, ID)
{
	window.location.href = "delete.php?ParentID="+ParentID+"&TblName=" + TblName+"&ID="+ID+"&Action=-1";
	return true;
}

function ShowRespose(xhttp)
{
	//alert(requester.responseText);
	if(xhttp.responseText != "" )
	{
		alert( xhttp.responseText);
	}
}


function getShortOver(xhttp)
{
		//alert(xhttp.responseText);
		if(xhttp.responseText != "" )
		{
			 document.getElementById('overshrtmsg').innerHTML = xhttp.responseText;
		}
}

function setShortOverMsg(id)
{ 
	//setInterval("update_shortover('"+id+"')", 3000);
	
	update_shortover(id);
	
}

//function setLogReport(id,ipp,xread)
function setLogReport(id)
{ 
	//setInterval("setLogReport2('"+id+"', '"+ipp+"','"+xread+"')",3000);
	
	//setInterval("setLogReport2('"+id+"')",3000);

	setLogReport2(id);

}


function SetPageRefresh(nSec)
{ 
	setInterval("javascript:window.location.reload();", nSec);
}